<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>文件上传API</title>
    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  	<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1";/><!-- IE的渲染模式 -->
  	<meta name="renderer" content="webkit"><!-- 浏览器高速模式 -->
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	  
	  
	 <script src="scripts/jquery/jquery-1.7.min.js"></script>

  </head>

<body>
	<h1>FileUpload Help</h1>
	
	<hr />
	<div>

		<p>
		<h3>1. 文件上传</h3>

		<form action="UploadAction?" method="post"
			ENCTYPE="multipart/form-data">
			目录：<input type="text" name="dir" value="temp/test" /> <input
				type="file" name="file" /> <input type="submit">
		</form>

		</p>

		<hr />

		<p>
		<h3>2. 文件过滤</h3>
		在Action中将配置好的 fileController 存入session。 如：PersonAction 中修改个人头像 S1:
		在PersonAction.java中配置fileController，存入session。
		<pre class="code java">
//头像上传过滤配置
fileController = new FileController(
		FileController.IMAGE_EXTS, //运行上传的文件类型是图片
		FileController.FileUploadMode.ALLOW, //过滤模式 allow
		1024*500L); // max size 500KB
fileController.setMsg("请上传图片文件，文件大小不大于500KB");
session.put("fileController", fileController);
		</pre>


		</p>

		<hr />

		<p>
		<h3>3. 上传回调</h3>
		<form action="UploadAction?callback=uploadcallback" method="post"
			ENCTYPE="multipart/form-data" target="hidden_frame">
			<input type=file name=file  /> <input
				type="text" name="dir" value="temp/test" /><br> <input
				type="submit">
			<div id="filepath"></div>
		</form>
		<iframe name="hidden_frame" style="display:none;"></iframe>
		<script>
					function uploadcallback(json){
			  			if(window.console)
			  				console.log(json);
			  			 
						if(json.error==0 || json.error==-2){
							if(json.data.length>=1)
							{
								if(json.data[0].error==0){
									var url = json.data[0].path;
									$("div#filepath").html( "<a href=\""+url+"\">"+url+"</a>" );
								}else{
									alert("上传失败["+json.data[0].msg+"]");
								}
							}else{
								alert("上传失败");
							}
						}else{
							alert(json.msg);
						}
					}
  		
				</script>
		</p>

		<hr />
		
		<p>
		
			<h3>文件过滤</h3>
			
			
			
			
		</p>
		
		<br />
		<br />
		<br />
		<br />
		<br />
		<br />


	</div>


	<div></div>



</body>
</html>
